package com.hddz.acquisition.barcode;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;

import jxl.Workbook;
import jxl.read.biff.BiffException;
import jxl.write.Label;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;
import jxl.write.WriteException;
import jxl.write.biff.RowsExceededException;

import android.app.ActivityManager;
import android.app.KeyguardManager;
import android.app.Service;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.jb.Preference;
import android.jb.barcode.BarcodeManager;
import android.jb.barcode.BarcodeManager.Callback;
import android.jb.barcode.BarcodeUntil;
import android.jb.utils.Tools;
import android.jb.utils.WakeLockUtil;
import android.net.Uri;
import android.os.Binder;
import android.os.Environment;
import android.os.Handler;
import android.os.IBinder;
import android.os.Message;
import android.text.TextUtils;
import android.util.Log;
import android.view.KeyEvent;
import android.widget.Toast;

import com.hddz.acquisition.R;

public class ScanService extends Service {

    private int scan_time_limit = 200; // 扫描间隔控制
    private static final String TAG = "ScanService";
    private boolean isActivityUp = false;
    private ActivityManager am;
    private ComponentName cn;
    private ScanListener mScanListener;
    private KeyguardManager km;
    private BarcodeManager scanManager = null;
    public static boolean keyF2DownOrNot = false;
    public static boolean isServiceOn = false;
    public static boolean isScanActivityUp = false; // 是否有Acitivty与服务绑定
    private boolean isScanShortcutSupport = false;
    private WakeLockUtil mWakeLockUtil = null;
    public static String uhfName = "com.jiebao.ht380k.uhf.UHFMainActivity";
    public static String chaobiaoName = "com.jiebao.ht380k.chaobiao.ChaoBiaoActivity";
    public static String rs232Name = "com.jiebao.ht380.rs232.RS232Activity";
    public static String psamName = "com.jiebao.ht380k.psam.PSamActivity";
    public static String uhfName2 = "com.jiebao.ht380k.uhf.UHFActivityMode2";
    public static String uhfName3 = "com.jiebao.ht380k.uhf.UHFActivityMode3";
    public static String scanName = "com.jiebao.ht380k.scan.ScanActivity";
    private FileOutputStream fileOutputStream;
    private File scanFile;
    private boolean sdCard;

    public BeepManager mBeepManager;
    private Intent webAddressintent;
    private Intent EditTextintent;
    private BarcodeUntil scanUtil;
    private WritableSheet mSheet;
    private WritableWorkbook mWorkbook;
    private Workbook mWorkbook1;
    private ArrayList<CurCell> mArrayList = new ArrayList<CurCell>();

    private class CurCell {
        int row;
        int col;
        String content;
    }

    ;

    public static String customActionKey;
    public static String customDataKey;
    public static String customCodeTypeKey;

    private Handler mHandler = new Handler() {
        @Override
        public void handleMessage(Message msg) {
            // TODO Auto-generated method stub
            switch (msg.what) {
                case 3001:
                    Toast.makeText(
                            ScanService.this,
                            getResources().getString(
                                    R.string.scan_init_failure_info), Toast.LENGTH_LONG).show();
                    break;

                default:
                    break;
            }
            super.handleMessage(msg);
        }
    };

    public void setActivityUp(boolean isActivityUp) {
        this.isActivityUp = isActivityUp;
    }

    @Override
    public void onCreate() {
        super.onCreate();
        isServiceOn = true;
        km = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
        System.out.println("Service onCreate()");
        mWakeLockUtil = new WakeLockUtil(this);
        am = (ActivityManager) getSystemService(ACTIVITY_SERVICE);

        IntentFilter intentFilter = new IntentFilter();
        intentFilter.addAction("com.jb.action.F4key");
        intentFilter.addAction("ReLoadCom");
        intentFilter.addAction("ReleaseCom");
        registerReceiver(f4Receiver, intentFilter);
        // 解决重新唤醒后 讯宝扫描乱码
        IntentFilter filter = new IntentFilter();
        filter.addAction(Intent.ACTION_SCREEN_ON);
        filter.addAction(Intent.ACTION_SCREEN_OFF);
        filter.addAction(Intent.ACTION_USER_PRESENT);
        registerReceiver(ScreenBroadcastReceiver, filter);
        System.out.println("onCreateend");

        if (Environment.getExternalStorageState().equals(
                Environment.MEDIA_MOUNTED)) {
            try {
                sdCard = true;
                File file = new File("mnt/sdcard/Scan Record");
                if (!file.exists()) {
                    file.mkdirs();
                }

                scanFile = new File("mnt/sdcard/" + "Scan Record" + "/"
                        + "Scan Record.txt");
                if (!scanFile.exists())
                    scanFile.createNewFile();
                fileOutputStream = new FileOutputStream(scanFile, true);

            } catch (FileNotFoundException e) {
                e.printStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
        mBeepManager = new BeepManager(this,
                Preference.getScanSound(this, true),
                Preference.getScanVibration(this, false));

        // if (Preference.getScannerModel(this) == BarcodeManager.MODEL_N3680) {
        // scan_time_limit = 500;
        // } else {
        // scan_time_limit = 100;
        // }

        IntentFilter jbScanFilter = new IntentFilter();
        jbScanFilter.addAction("com.jb.action.SCAN_SWITCH");
        jbScanFilter.addAction("com.jb.action.START_SCAN");
        jbScanFilter.addAction("com.jb.action.STOP_SCAN");
        jbScanFilter.addAction("com.jb.action.START_SCAN_CONTINUE");
        jbScanFilter.addAction("com.jb.action.STOP_SCAN_CONTINUE");
        this.registerReceiver(jbScanReceiver, jbScanFilter);


        customActionKey = Preference.getCustomCBAction(ScanService.this, "");
        customDataKey = Preference.getCustomCBData(ScanService.this, "");
        customCodeTypeKey = Preference.getCustomCBCodeType(ScanService.this, "");

        Log.e(TAG, "customActionKey " + customActionKey);
        Log.e(TAG, "customDataKey " + customDataKey);
        Log.e(TAG, "customCodeTypeKey " + customCodeTypeKey);

    }

    @Override
    @Deprecated
    public void onStart(Intent intent, int startId) {
        // TODO Auto-generated method stub
        super.onStart(intent, startId);
        isScanShortcutSupport = Preference.getScanShortcutSupport(this, true);
        if (scanManager == null) {
            scanManager = BarcodeManager.getInstance();
        } else {
            // if (scanManager.isSerialPort_isOpen()) {
            scanManager.Barcode_Close();
            try {
                Thread.sleep(500);
            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            // }
        }
        Log.e(TAG, "onStart()");
        scanManager.Barcode_Open(ScanService.this, dataReceived);
        try {
            Thread.sleep(500);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("Service onStart()");
    }

    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        // TODO Auto-generated method stub
        System.out.println("Service onStartCommand()");
        return super.onStartCommand(intent, flags, startId);
    }

    public BarcodeManager getScanManager() {
        if (null == scanManager) {
            scanManager = BarcodeManager.getInstance();
            Log.e(TAG, "getScanManager()");
            scanManager.Barcode_Open(ScanService.this, dataReceived);
            // scanManager.SetReadListener(dataReceived);
        }
        return scanManager;
    }

    /**
     * 扫描数据接收类
     *
     * @author Administrator
     */
    Callback dataReceived = new Callback() {

        @Override
        public void Barcode_Read(byte[] buffer, String codeId, int errorCode) {

            mBeepManager.play();
            String codeType = Tools.returnType(buffer);
            String val = null;

            Log.e("jiebao", "buffer.length " + buffer.length);
            for (int i = 0; i < buffer.length; i++) {
                Log.e("jiebao", "buffer[" + i + "] = " + Integer.toHexString(buffer[i] & 0xFF));
            }

            if (codeType.equals("default")) {
                val = new String(buffer);
            } else {
                try {
                    val = new String(buffer, codeType);
                } catch (UnsupportedEncodingException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }


            byte valBuffer[] = val.getBytes();
            for (int i = 0; i < val.length(); i++) {
                Log.e("jiebao", "valBuffer[" + i + "] = " + Integer.toHexString(valBuffer[i] & 0xFF));
            }


            if (null != mScanListener) {
                System.out.println("val:" + val);
                mScanListener.henResult(codeId, val);
            }

            Log.v(TAG, "Barcode_Read isActivityUp: " + isActivityUp);
            if (null != scanManager) {
                if (!isActivityUp) {
                    houtai_result(codeId, val);
                }
            }

            if (sdCard && getScanSaveTxt()) {
                scanUtil = new BarcodeUntil();
                scanUtil.setScanDate(Tools.getNowTimeString());
                scanUtil.setScanResult(val);
                saveInTxt(scanUtil.getScanResult() + "\n"
                        + "Scan time" + ": " + scanUtil.getScanDate() + "\n");
            }

            Log.e(TAG, "getScanSaveExl258: " + getScanSaveExl());
            if (getScanSaveExl()) {
                Log.e(TAG, "getScanSaveExl259: " + getScanSaveExl());
                addToArray(val);
                WriteExcel();
            }
//			Log.e(TAG, "onDataReceived val:" + val);
        }
    };

    private void WriteExcel() {
        try {
            File scanFile = new File("/mnt/sdcard/scan.xls");
            Log.e(TAG, " WriteExcel scanFile: " + scanFile.exists());
            if (scanFile.exists()) {
                mWorkbook1 = Workbook.getWorkbook(scanFile);
                mWorkbook = Workbook.createWorkbook(scanFile, mWorkbook1);
                mSheet = mWorkbook.getSheet(0);
            } else {
                mWorkbook = Workbook.createWorkbook(scanFile);
                mSheet = mWorkbook.createSheet("scan", 0);
            }
            for (CurCell mCurCell : mArrayList) {
                Label mLabel = new Label(mCurCell.col, mCurCell.row, mCurCell.content);
                mSheet.addCell(mLabel);
            }
//				int row = mArrayList.get(mArrayList.size() - 1).row;
//				int col = mArrayList.get(mArrayList.size() - 1).col;
            if (null != mWorkbook) {
                mWorkbook.write();
                mWorkbook.close();
            }
            if (null != mWorkbook1)
                mWorkbook1.close();
        } catch (RowsExceededException e) {
            e.printStackTrace();
        } catch (WriteException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (BiffException e) {
            e.printStackTrace();
        }
    }

    private void addToArray(String content) {
        Log.e(TAG, " addToArray mSheet: " + mSheet);
        if (mSheet == null)
            initExcel();
        if (mSheet != null) {
            CurCell mCurCell1 = new CurCell();
            mCurCell1.col = 0;//列
            mCurCell1.row = mSheet.getRows();//行
            mCurCell1.content = content;
            CurCell mCurCell2 = new CurCell();
            mCurCell2.col = 1;
            mCurCell2.row = mSheet.getRows();
            mCurCell2.content = Tools.getNowTimeString();
            mArrayList.add(mCurCell1);
            mArrayList.add(mCurCell2);
        }
    }

    private void initExcel() {
        // TODO Auto-generated method stub
        CurCell mCurCell1 = new CurCell();
        mCurCell1.col = 0;
        mCurCell1.row = 0;
        mCurCell1.content = "Code";
        CurCell mCurCell2 = new CurCell();
        mCurCell2.col = 1;
        mCurCell2.row = 0;
        mCurCell2.content = "Scan Time";
        mArrayList.add(mCurCell1);
        mArrayList.add(mCurCell2);
        WriteExcel();
    }

    public void setOnScanListener(ScanListener scanListener) {
        this.mScanListener = scanListener;

    }

    public Binder myBinder = new MyBinder();

    public class MyBinder extends Binder {

        public ScanService getService() {

            return ScanService.this;
        }
    }

    @Override
    public IBinder onBind(Intent intent) {
        return myBinder;
    }

    long nowTime = 0;
    long lastTime = 0;
    /**
     * 捕获扫描物理按键广播
     */
    private BroadcastReceiver f4Receiver = new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {
            if ("ReLoadCom".equals(intent.getAction())) {
                System.out.println("ReLoadCom()");
                if (scanManager != null) {
                    scanManager.Barcode_Close();
                    scanManager = BarcodeManager.getInstance();
                    Log.e(TAG, "ReLoadCom");
                    scanManager.Barcode_Open(ScanService.this, dataReceived);
                    System.out.println("scanManager.init()");
                }
                // init();
                return;
            }
            if ("ReleaseCom".equals(intent.getAction())) {
                System.out.println("ReleaseCom()");
                if (scanManager != null) {
                    scanManager.Barcode_Close();
                }
                return;
            }
            if (km.inKeyguardRestrictedInputMode()) {// 屏已锁
                System.out.println("lock");
                return;
            }
            // Bundle bundle = intent.getExtras();
            if (intent.hasExtra("F4key")) {
                if (intent.getStringExtra("F4key").equals("down")) {
                    Log.e("trig", "key down11111");
                    keyF2DownOrNot = true;
                    mHandler.removeCallbacks(stopKeyDown);
                    if (null != scanManager) {
                        if (getScanShortcutSupport()) {
                            nowTime = System.currentTimeMillis();
                            mWakeLockUtil.lock();

                            if (nowTime - lastTime > scan_time_limit) {
                                Log.e("ScanService trig", "key down");
                                scanManager.Barcode_Stop();

                                lastTime = nowTime;
                                scanManager.Barcode_Start();
                            }
                        }
                    }
                } else if (intent.getStringExtra("F4key").equals("up")) {
                    Log.e("trig", "key up");
                    if (null != scanManager) {
                        if (getScanShortcutSupport()
                                && getScanShortCutMode().equals("2")) {
                            mWakeLockUtil.unLock();
                            mHandler.postDelayed(stopKeyDown, 1000);
                            if (Preference
                                    .getScanShortCutPressMode(ScanService.this) == 2) {
                                scanManager.Barcode_Stop();
                            }
                        }
                    }
                }
            }
        }
    };

    private BroadcastReceiver ScreenBroadcastReceiver = new BroadcastReceiver() {
        private String action = null;

        @Override
        public void onReceive(Context context, Intent intent) {
            action = intent.getAction();
            if (Intent.ACTION_SCREEN_ON.equals(action)) {
                // 开屏
                System.out.println("ACTION_SCREEN_ON");
                if (!checkIsInFirst()) {
                    if (scanManager == null) {
                        scanManager = BarcodeManager.getInstance();
                    } else {
                        // if (scanManager.isSerialPort_isOpen()) {
                        scanManager.Barcode_Close();
                        try {
                            Thread.sleep(500);
                        } catch (InterruptedException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        }
                        // }
                    }
                    // Log.e(TAG, "ACTION_SCREEN_ON()");
                    scanManager.Barcode_Open(ScanService.this, dataReceived);
                    // scanManager.SetReadListener(dataReceived);
                    System.out.println("scanManager.init()");
                }
            } else if (Intent.ACTION_SCREEN_OFF.equals(action)) {
                // 锁屏
                System.out.println("ACTION_SCREEN_OFF");
                // 以防别使用该的串口的被下电s
                if (!checkIsInFirst()) {
                    if (scanManager != null) {
                        scanManager.Barcode_Close();
                        scanManager.Barcode_Stop();
                        // scanManager = null;
                    }
                }
                // scanManager.power("0");
            } else if (Intent.ACTION_USER_PRESENT.equals(intent.getAction())) {
                System.out.println("ACTION_USER_PRESENT");
            }
        }
    };

    private BroadcastReceiver jbScanReceiver = new BroadcastReceiver() {
        public void onReceive(Context context, Intent intent) {
            if ("com.jb.action.SCAN_SWITCH".equals(intent.getAction())
                    && intent.hasExtra("extra")) {
                int extra = intent.getIntExtra("extra", -1);
                if (extra == 1) {
                    if (null != scanManager) {
                        scanManager
                                .Barcode_Open(ScanService.this, dataReceived);
                    }
                } else if (extra == 0) {
                    if (null != scanManager) {
                        scanManager.Barcode_Close();
                    }
                }
            }
            if ("com.jb.action.START_SCAN".equals(intent.getAction())) {
                keyF2DownOrNot = true;
                mHandler.removeCallbacks(stopKeyDown);
                if (null != scanManager) {
                    scanManager.Barcode_Start();
                }
            }
            if ("com.jb.action.STOP_SCAN".equals(intent.getAction())) {
                mHandler.postDelayed(stopKeyDown, 1000);
                if (null != scanManager) {
                    scanManager.Barcode_Stop();
                }
            }
            if ("com.jb.action.START_SCAN_CONTINUE".equals(intent.getAction())) {
                long continue_interval = 1000;
                if (intent.hasExtra("continue_interval")) {
                    continue_interval = intent.getIntExtra("continue_interval", 1000);
                    Log.d("ScanService", "continue_interval:" + continue_interval);
                }
                if (null != scanManager) {
                    scanManager.Barcode_Continue_Start(continue_interval);
                }
            }
            if ("com.jb.action.STOP_SCAN_CONTINUE".equals(intent.getAction())) {
                if (null != scanManager) {
                    scanManager.Barcode_Continue_Stop();
                }
            }
        }

        ;
    };

    @Override
    public void onDestroy() {
        super.onDestroy();

        scanManager.Barcode_Close();
        scanManager.Barcode_Stop();
        unregisterReceiver(f4Receiver);
        unregisterReceiver(ScreenBroadcastReceiver);
        unregisterReceiver(jbScanReceiver);
        // power("0");
        // scan("1");
        Log.i(TAG, "onDestroy");
        mWakeLockUtil.unLock();
        sendBroadcast(new Intent("ScanServiceDestroy"));
        // unregisterReceiver(screenOnBroadcastReceiver);
        System.err.println("ScanService_Destroy");
        isServiceOn = false;
    }

    private Runnable stopKeyDown = new Runnable() {

        @Override
        public void run() {
            // System.out.println("keyF2DownOrNot:" + keyF2DownOrNot);
            keyF2DownOrNot = false;
        }
    };

    /**
     * 检查最上层Activity 是否为使用相同串口Activity 防冲突
     *
     * @return
     */
    private boolean checkIsInFirst() {
        cn = am.getRunningTasks(1).get(0).topActivity;
        Log.d("", "pkg:" + cn.getPackageName());
        Log.d("", "cls:" + cn.getClassName());
        if (cn.getClassName().equals(rs232Name)
                || cn.getClassName().equals(psamName)
                || cn.getClassName().equals(chaobiaoName)
                || cn.getClassName().equals(uhfName)
                || cn.getClassName().equals(uhfName2)
                || cn.getClassName().equals(uhfName3))
            return true;
        return false;
    }


    /**
     * 将内容显示到文本框
     *
     * @param dataStr
     */
    public void sendEditTextBroadcast(String dataStr) {
        // TODO Auto-generated method stub
        // webAddressHandler(dataStr);
//		int suffixModel = Preference.getScanSuffixModel(this,ScanSetupActivity.SuffixModel_None);
//
//		StringBuilder sb = new StringBuilder();
//		sb.append(dataStr);
//		EditTextintent = new Intent("com.haier.DeITTEXT");
//
//		Log.e("jiebao", "sb.length() " + sb.length());
//		byte b1[] = sb.toString().getBytes();
//        for(int i = 0; i < sb.length(); i++) {
//            Log.e("jiebao", "b1[" + i + "] = " + Integer.toHexString(b1[i]&0xFF));
//        }


//		switch (suffixModel) {
//			case ScanSetupActivity.SuffixModel_Enter:
//                sb.append("\r");
//				byte b2[] = sb.toString().getBytes();
//                for(int i = 0; i < sb.length(); i++) {
//                    Log.e("jiebao", "SuffixModel_Enter b2[" + i + "] = " + Integer.toHexString(b2[i]&0xFF));
//                }
//
//				EditTextintent.putExtra("showvalue", sb.toString());
//				this.sendBroadcast(EditTextintent);
//				break;

//			case ScanSetupActivity.SuffixModel_Semicolon:
//				sb.append(";");
//				byte b3[] = sb.toString().getBytes();
//                for(int i = 0; i < sb.length(); i++) {
//                    Log.e("jiebao", "SuffixModel_Semicolon b3[" + i + "] = " + Integer.toHexString(b3[i]&0xFF));
//                }
//
//				EditTextintent.putExtra("showvalue", sb.toString());
//				this.sendBroadcast(EditTextintent);
//				break;
//
//			case ScanSetupActivity.SuffixModel_Tab:
//				sb.append("\t");
//				byte b4[] = sb.toString().getBytes();
//                for(int i = 0; i < sb.length(); i++) {
//                    Log.e("jiebao", "SuffixModel_Tab b4[" + i + "] = " + Integer.toHexString(b4[i]&0xFF));
//                }
//
//				EditTextintent.putExtra("showvalue", sb.toString());
//				this.sendBroadcast(EditTextintent);
//				break;

//			default:
//				EditTextintent.putExtra("showvalue", sb.toString());
//				this.sendBroadcast(EditTextintent);
//				break;
//		}
    }

    /**
     * 将内容发送广播
     *
     * @param dataStr
     */
    public void sendScanBroadcast(String codeid, String dataStr) {
        // TODO Auto-generated method stub

        Intent scanDataIntent = new Intent("com.jb.action.GET_SCANDATA");
        scanDataIntent.putExtra("data", dataStr);
        scanDataIntent.putExtra("codetype", codeid);
        this.sendBroadcast(scanDataIntent);

        if (TextUtils.isEmpty(customActionKey) || TextUtils.isEmpty(customDataKey) || TextUtils.isEmpty(customCodeTypeKey)) {

        } else {
            Intent customCBInter = scanDataIntent = new Intent(customActionKey);
            customCBInter.putExtra(customDataKey, dataStr);
            customCBInter.putExtra(customCodeTypeKey, codeid);
            this.sendBroadcast(customCBInter);
            Log.d(TAG, "send cutom cb action" + customActionKey);
            Log.d(TAG, "send cutom cb customDataKey" + customDataKey + " : " + dataStr);
            Log.d(TAG, "send cutom cb customCodeTypeKey" + customCodeTypeKey + " : " + codeid);
        }

    }

    /**
     * 网页支持
     *
     * @param dataStr
     */
    public void webAddressHandler(String dataStr) {
        try {
            webAddressintent = new Intent();
            webAddressintent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            webAddressintent.setAction("android.intent.action.VIEW");
            //Uri content_url = Uri.parse(dataStr);
            Uri content_url = Uri.parse("http://www.baidu.com/s?ie=utf8&word=" + dataStr);
            webAddressintent.setData(content_url);
            this.startActivity(webAddressintent);
        } catch (Exception e) {
            // TODO: handle exception
        }
    }

    /**
     * 扫描内容保存至TXT
     *
     * @param data
     */
    public void saveInTxt(String data) {
        byte[] bytes = data.getBytes();
        try {
            fileOutputStream.write(bytes);
            fileOutputStream.flush();

        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    public void houtai_result(String codeid, String data) {

        Log.e("jiebao", "houtai_result data " + data);


        if (data != null && !data.trim().equals("")) {
            int out_mode = getScanOutMode();

            switch (out_mode) {
                case 3:
                    sendScanBroadcast(codeid, data);
                    break;

                case 2:
                    break;

                case 1:
                    sendEditTextBroadcast(data);
                    break;

                default:
                    break;
            }

            Log.v(TAG, "houtai_result getScanNetSupport: " + getScanNetSupport());
            if (getScanNetSupport()) {
                webAddressHandler(data);
            }
        }
    }

    /**
     * 是否支持扫描快捷键 默认支持
     *
     * @return <code>true</code> 支持 <code>false</code>不支持
     */
    public boolean getScanShortcutSupport() {
        return isScanShortcutSupport;
    }

    /**
     * 是否支持网页扫描 默认不支持
     *
     * @return <code>true</code> 支持 <code>false</code>不支持
     */
    public boolean getScanNetSupport() {
        return Preference.getNetPageSupport(this, false);
    }

    /**
     * 支持扫描快捷自定义后缀 默认后缀回车 -1:无后缀 0：回车 1：分号
     */
    public int getScanSuffixModel() {
//		return Preference.getScanSuffixModel(this,
//				ScanSetupActivity.SuffixModel_Enter);
        return -1;
    }

    /**
     * 是否支持扫描记录保存至TXT文档 默认不支持 <code>true</code> 支持 <code>false</code> 不支持
     */
    public boolean getScanSaveTxt() {
        return Preference.getScanSaveTxt(this, false);
    }

    /**
     * 是否支持扫描记录保存至EXL文档 默认不支持 <code>true</code> 支持 <code>false</code> 不支持
     */
    public boolean getScanSaveExl() {
        return Preference.getScanSaveExl(this, false);
    }

    /**
     * 获取扫描快捷键 默认为中间橙色按键
     * <p>
     * 1:左侧橙色按键 2:中间橙色按键 3:右边橙色按键
     */
    public String getScanShortCutMode() {
        return Preference.getScanShortcutMode(this, "2");
    }

    /**
     * 后台扫描输出模式 默认快速扫描
     * <p>
     * 1.快速扫描（文本框） 2.模拟键盘 3.广播
     */
    public int getScanOutMode() {
        return Preference.getScanOutMode(this);
    }

    public void setIsScanShortcutSupport(boolean isScanShortcutSupport) {
        this.isScanShortcutSupport = isScanShortcutSupport;
    }
}
